package com.wasion.pwportable.protocol;

public class Protocol {

	public static final int CURRENT_CAL_REF = 5;
	public static final int CUTOFF_CURRENTREF = 5;
	public static final int GROUND_CUT_CURRENTREF = 1;

	// 调试盒地址获取
	public static String AddressQurey_Code = "7E01028116";

	// 调试盒超时回应
	public static final String TIMEOUT_Frame = "EEEEEEEEEEEEEEEEEEEE";

	// 架空型频率
	public static String[] channeList = new String[] { "    ", "频率1", "频率2",
			"频率3", "频率4", "频率5", "频率6", "频率7", "频率8", "频率9" };

	// 数据长度
	public static final String DEV_ADDR_WR_LENGTH = "0A";

	public static final String CABLE_TEMP_RD = "3D"; // 电缆型 读温度标识

	public static String SENDERID = ""; // 设备本身相关信息
	public static String RECEIVERID = ""; // 设备本身相关信息

	// 标识符规定
	// 头尾 定义
	public static final String FRAEMHEAD = "7E"; // 帧头
	public static final String FRAMETAIL = "16"; // 帧尾

	// 功能标识符开始和结束位
	protected static final int DATATPYESTARTBIT = 10;
	protected static final int DATATPYENDBIT = 12;

	public static String DEV_INFO_RD = "1F"; // 设备本身相关信息

	public static String DEV_INFO_RD_FOR_PRODUCTION = "95"; // 设备本身相关信息 生产测试专用

	public static String DEV_ADDR_RD = "1D"; // 设备地址信信息的查询
	public static String DEV_ADDR_WR = "1E"; // 设备地址信信息的设置

	public static String RUNNING_PARAM_RD = "2C"; // 运行参数读取
	public static String RUNNING_PARAM_WR = "2D"; // 运行参数设置

	public static String TURETIME_RD = "2E"; // 翻牌复归时间查询
	public static String TURETIME_WR = "2F"; // 翻牌复归时间设置

	public static String STATUS_RD = "30"; // 节点运行状态信息
	public static String BATTERY_RD = "32"; // 实时电池容量
	public static String CAPACITY_RD = "31"; // 法拉电容电量
	public static final String CABLE_DATA_RD = "3D"; // 电缆型实时数据
	public static final String GROUND_MUTATION_RD = "3E"; // 接地电流突变量
	public static final String CURRENT_RD = "3F"; // 平均电流
	public static final String RSSI_RD = "74"; // 信号接收强度

	public static String FLIP_ACTION = "50"; // 翻牌复归测试
	public static String FLIP_DATA = "55"; // 翻牌 命令数据 是 0x55
	public static String TURNBACK_DATA = "AA"; // 复归命令数据 是 0xAA

	public static String FAULT_ALTER = "66"; // 故障告警

	public static String NEIGHBOR_INFO_RD = "6E"; // 节点相邻属性信息 查
	public static String NEIGHBOR_INFO_WR = "6F"; // 节点相邻属性信息 设

	public static String RELAY_INFO_RD = "6C"; // 节点中继相关信息 查
	public static String RELAY_INFO_WR = "6D"; // 节点中继相关信息 设

	public static String WAKEUP_TYPE = "AA"; // 唤醒帧数据标识

	public static String SLEEP_TIME_RD = "72";
	public static String SLEEP_TIME_WR = "73";

	public static String GROUNDED_FLIP_RD = "23";
	public static String GROUNDED_FLIP_WR = "24"; // 数据位 2字节

	public static String GROUND_DETAL_RD = "25";
	public static String GROUND_DETAL_WR = "26"; // 数据位1字节 (A)

	public static String GROUNNDED_TIME_RD = "27"; // 数据位2字节 (ms)
	public static String GRROUNDED_TIME_WR = "28";

	// 架空型 指示器 生产参数信息
	public static String AIR_FACTORY_PARAMS_RD = "90"; // 数据位2字节 (ms)
	public static String AIR_FACTORY_PARAMS_WR = "91";

	// 电缆型 指示器 生产参数
	public static String CABLE_FACTORY_PARAMS_RD = "3A"; // 数据位2字节 (ms)
	public static String CABLE_FACTORY_PARAMS_WR = "3B";

	public static String INDICATOR_REBOOT = "79";

	// 终端 的 命令
	public static String NETWORK_FILE_WR = "F0"; // 组网档案信息下发
	public static String NETWORK_FILE_RD = "F1"; // 组网档案信息查询

	public static String NETWORK_STATUS = "F3"; // 组网状态查询
	public static String NETWORK_SET = "F2";
	public static String NETWORK_DATA_STOP = "01"; // 组网 :0 停止 1启动 2 重启命令
	public static String NETWORK_DATA_START = "00"; // 组网: 0 停止 1启动 2 重启命令
//	public static String NETWORK_DATA_RESTART = "02"; // 组网 :0 停止 1启动 2 重启命令

	public static String T_AREA_CODE_RD = "D0"; // 区县码 查询
	public static String T_AREA_CODE_WR = "D1"; // 区县码 设置

	public static String T_COMMUNICATIONS_RD = "D2"; // 通讯信息查询
	public static String T_COMMUNICATIONS_WR = "D3"; // 通讯设置

	public static String TERMINAL_TIME_WR = "D8"; // 时间日期查询
	public static String TERMINAL_TIME_RD = "D7"; // 时间日期设置

	public static String TERMINAL_RESET = "D9"; // 终端复位

	public static String T_LAST_GATHER = "DB"; // 最后一次定采完成情况

	public static String T_CAP2CT_RD = "DE"; // 电容电压和CT电压

	public static String T_Version_RD = "DA"; // 终端版本查询

	// 配网遥信终端 主站IP地址
	public static String HOST_IP_RD = "D2"; // 查询
	public static String HOST_IP_WR = "D3"; // 设置

	public static String T_USER_PASSWOR_RD = "D4"; // 用户密码查询
	public static String T_USER_PASSWOR_WR = "D5"; // 用户密码设置

	public static String T_COMM_CONTROL_RD = "DC"; // 通信管控查询
	public static String T_COMM_CONTROL_WR = "DD"; // 通信管控设置

	public static String T_COMM_CONTROL_YES = "01";
	public static String T_COMM_CONTROL_NO = "00";

	public static String REG_STATUS_RD = "D6"; // 上行通道注册状态

	// 中继级数和数据有效位
	public static final String RELAY_GRADE = "09"; // 点对点时固定
	public static final String VALIDATE_BIT = "01"; // 点对点时固定

	public static final String PREUPDATE_IDENTIFIER = "A0"; // 升级标识帧 标识
	public static final String PREUPDATE_LENGTH = "0A"; // 升级标识帧长度
	public static final String PREUPDATE_REQUEST = "AA"; // 升级标识 启动
	public static final String PREUPDATE_SUCCESS = "00"; // 升级标识结果 成功

	public static final String UPDATE_IDENTIFIER = "A3";

	public static final String FILE_REQUEST_LENGTH = "17";
	public static final String FILE_REQUEST_IDENTIFIER = "A2";
	public static final String FILE_REQUEST__SUCCESS = "00"; // 读文件成功

	public static final String REBOOT_IDICATOR = "79";
	public static final String REBOOT_IDICATOR_DATA = "01";
	public static final String RESTART_LENGTH = "0A";

	public static final String NORMAL_LENGTH = "09";
	public static final String DEVICE_IDENTIFIER = "1F";

	public static final String VERSION_DEFAULT = "default";

	public static final String CHANNEL_RD = "75";
	public static final String CHANNEL_WR = "76";

	public static final String INDI_TIME_RD = "11";
	public static final String INDI_TIME_WR = "12";

	public static final String ELECTRIC_FIELD_RD = "15";
	public static final String ELECTRIC_FIELD_WR = "16";

	public static final String STARTUP_PARAMS_RD = "17";
	public static final String STARTUP_PARAMS_WR = "18";

	public static final String EPROM_RD = "13";

	public static final String TEMP_VAVLE_RD = "21";
	public static final String TEMP_VAVLE_WR = "22";

	public static final String STARTUP_CURRENT_RD = "23";
	public static final String STARTUP_CURRENT_WR = "24";

	public static final String GROUND_RISE_RD = "25";
	public static final String GROUND_RISE_WR = "26";

	public static final String GROUND_MAXTIME_RD = "27";
	public static final String GROUND_MAXTIME_WR = "28";

	public static final String ZERO_SEQUENCE_RD = "2A";
	public static final String ZERO_SEQUENCE_WR = "2B";

	public static final String CAPCITY_RD = "31";
	public static final String BETTERY_RD = "32";
	public static final String MAGNETIC_RD = "9A";

	public static final String ShortFault_RD = "37";
	public static final String GroundFault_RD = "38";
	public static final String OverHeat_RD = "39";

	public static final String CURRENT_PARAMS_RD = "4E";
	public static final String CURRENT_PARAMS_WR = "4F";

	public static final String TRIVAL_CURRENT_PARAMS_RD = "4C";
	public static final String TRIVAL_CURRENT_PARAMS_WR = "4D";

	public static final String ZERO_CURRENT_PARAMS_RD = "4C";
	public static final String ZERO_CURRENT_PARAMS_WR = "4D";

	public static final String LINE_FAULT_RD = "77";
	public static final String DEICE_FAULT_RD = "78";

	public static final String GROUND_ELECTRIC_FIELD_RD = "7A";
	public static final String GROUND_TEMP_CURRENT_RD = "7B";
	public static final String GROUND_TEMP_CURRENT_RD2 = "7C";
	public static final String GROUND_SAMPLE_RD = "7D";
	public static final String LAST_GROUND_TIME_RD = "71";

	public static final String LAST_SHORT_INFO_RD = "7E";
	public static final String LAST_SHORT_CURRENT_RD = "7F";
	public static final String SHORT_ELECTRIC_FIELD_RD = "82";
	public static final String CHIP_TEMP_RD = "85";
	public static final String SHORT_FAULT_STATUS_RD = "86";

	public static final String DATA_FRAME_FAULT_COUNT_RD = "87";
	public static final String SHORT_SAMPLE_RD = "88";

	public static final String START_BITS_RD = "89";
	public static final String START_BITS_WR = "8A";

	public static final String ERASE_PARAMS = "92";
	public static final String ERASE_DATA = "93";

	public static final String MODULE_MODE_RD = "96";
	public static final String MODULE_MODE_RW = "97";

	// 开始信号标识
	public static final String DATA_FCI_TIME_BEGIN = "A8";

	// 架空型故障指示器负荷电流数据记录 当天、上一日、上二日
	public static final String DATA_MINUX_T0DAY_CUR_1 = "B0";
	public static final String DATA_MINUX_T0DAY_CUR_2 = "B1";
	public static final String DATA_MINUX_T0DAY_CUR_3 = "B2";
	public static final String DATA_MINUX_T0DAY_CUR_4 = "B3";
	public static final String DATA_MINUX_T0DAY_CUR_5 = "B4";
	public static final String DATA_MINUX_T0DAY_CUR_6 = "B5";
	public static final String DATA_MINUX_T0DAY_CUR_7 = "B6";
	public static final String DATA_MINUX_T0DAY_CUR_8 = "B7";
	public static final String DATA_MINUX_T0DAY_CUR_9 = "B8";
	public static final String DATA_MINUX_T0DAY_CUR_10 = "B9";
	public static final String DATA_MINUX_T0DAY_CUR_11 = "BA";
	public static final String DATA_MINUX_T0DAY_CUR_12 = "BB";
	public static final String DATA_MINUX_T0DAY_CUR_13 = "BC";
	public static final String DATA_MINUX_T0DAY_CUR_14 = "BD";
	public static final String DATA_MINUX_T0DAY_CUR_15 = "BE";
	public static final String DATA_MINUX_T0DAY_CUR_16 = "BF";

	public static final String DATA_MINUX_1_DAY_CUR_1 = "C0";
	public static final String DATA_MINUX_1_DAY_CUR_2 = "C1";
	public static final String DATA_MINUX_1_DAY_CUR_3 = "C2";
	public static final String DATA_MINUX_1_DAY_CUR_4 = "C3";
	public static final String DATA_MINUX_1_DAY_CUR_5 = "C4";
	public static final String DATA_MINUX_1_DAY_CUR_6 = "C5";
	public static final String DATA_MINUX_1_DAY_CUR_7 = "C6";
	public static final String DATA_MINUX_1_DAY_CUR_8 = "C7";
	public static final String DATA_MINUX_1_DAY_CUR_9 = "C8";
	public static final String DATA_MINUX_1_DAY_CUR_10 = "C9";
	public static final String DATA_MINUX_1_DAY_CUR_11 = "CA";
	public static final String DATA_MINUX_1_DAY_CUR_12 = "CB";
	public static final String DATA_MINUX_1_DAY_CUR_13 = "CC";
	public static final String DATA_MINUX_1_DAY_CUR_14 = "CD";
	public static final String DATA_MINUX_1_DAY_CUR_15 = "CE";
	public static final String DATA_MINUX_1_DAY_CUR_16 = "CF";

	public static final String DATA_MINUX_2_DAY_CUR_1 = "D0";
	public static final String DATA_MINUX_2_DAY_CUR_2 = "D1";
	public static final String DATA_MINUX_2_DAY_CUR_3 = "D2";
	public static final String DATA_MINUX_2_DAY_CUR_4 = "D3";
	public static final String DATA_MINUX_2_DAY_CUR_5 = "D4";
	public static final String DATA_MINUX_2_DAY_CUR_6 = "D5";
	public static final String DATA_MINUX_2_DAY_CUR_7 = "D6";
	public static final String DATA_MINUX_2_DAY_CUR_8 = "D7";
	public static final String DATA_MINUX_2_DAY_CUR_9 = "D8";
	public static final String DATA_MINUX_2_DAY_CUR_10 = "D9";
	public static final String DATA_MINUX_2_DAY_CUR_11 = "DA";
	public static final String DATA_MINUX_2_DAY_CUR_12 = "DB";
	public static final String DATA_MINUX_2_DAY_CUR_13 = "DC";
	public static final String DATA_MINUX_2_DAY_CUR_14 = "DD";
	public static final String DATA_MINUX_2_DAY_CUR_15 = "DE";
	public static final String DATA_MINUX_2_DAY_CUR_16 = "DF";

	// 复位架空型故障指示器负荷电流数据记录的索引标识
	public static final String LOAD_CURRENT_RESET = "C5";

	// 调试盒类型设置
	public static final String[] modeCommands = { "7E0208008816", // 0
			"7E0208018916", // 1
			"7E0208028A16", // 2
			"7E0208038B16", // 3
			"7E0208048C16", // 4
			"7E0208058D16" // 5
	};

	public static String PROTOCOL_VERSION = VERSION_DEFAULT;

	public static final String READ_FRAME_LENGTH = "09";

	public static String DATA_LENGTH = READ_FRAME_LENGTH; // 点对点查询，

	public static final String RESTART_IDENTIFIER = "79";

	// 各种类型帧长度
	public static final String WAKEUPFRAMELENTH = "0A"; // 唤醒帧长
	public static final String CURRENTFRAMELENTH = "0A"; // 查询电流的回应帧长度

	// 帧 的 应用数据域
	public static final String WAKEUPDATABYTES = "0A"; // OA
	// 表示wakeup
	// 动作命令，物理层会解析并产生动作
	public static final String WOKEUPDATABYTES = "E0"; // E0
	// 表示
	// 已经被唤醒。。
	public static final String CURRENT_DATA = READ_FRAME_LENGTH; // 点对点，
	// 下发

	public static final String CHANNEL = "01"; // 电缆型指示器通信的回路（频道）

	public static String channels[] = { "00", "01", "02", "03", "04", "05",
			"06", "07", "08", "09", "10" };

	// 读调试盒频道命令
	public static final String GET_Channel_IDENTIFIER = "0405";

	/**
	 * @param localAddress
	 * @return
	 */
	public static String resortAddress(String localAddress) {
		String displayAddress = localAddress.substring(4, 6)
				+ localAddress.substring(2, 4) + localAddress.substring(0, 2);
		return displayAddress;
	}

	/**
	 * @param localAddress
	 * @return
	 */
	public static String toRealAddress(String displayAddress) {
		if (null != displayAddress && displayAddress.length() >= 6) {
			String realAddress = displayAddress.substring(4, 6)
					+ displayAddress.substring(2, 4)
					+ displayAddress.substring(0, 2);
			return realAddress.toUpperCase();
		}

		return "";

	}
}
